package io.mvvm.common.handler;

import io.mvvm.common.enumerate.ResponseEnum;
import io.mvvm.common.entity.AjaxResponse;
import io.mvvm.security.global.ForciblyLoginException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: seize-login
 * @description: 全局异常处理
 * @author: 潘
 * @create: 2021-05-16 12:07
 **/
@ControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {
    private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(ForciblyLoginException.class)
    public AjaxResponse myExceptionHandler(ForciblyLoginException ex) {
        ResponseEnum forciblyLoginError = ResponseEnum.FORCIBLY_LOGIN_ERROR;
        return AjaxResponse.builder().code(forciblyLoginError.getCode()).msg(forciblyLoginError.getMessage()).build();
    }

}
